package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.INodeRoleService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.NodeRoleCreateValidate;
import com.mdd.admin.validate.NodeRoleUpdateValidate;
import com.mdd.admin.validate.NodeRoleSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.NodeRoleListedVo;
import com.mdd.admin.vo.NodeRoleDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/nodeRole")
@Api(tags = "节点用户、角色、岗位关联管理")
public class NodeRoleController {

    @Resource
    INodeRoleService iNodeRoleService;

    @GetMapping("/list")
    @ApiOperation(value="节点用户、角色、岗位关联列表")
    public AjaxResult<PageResult<NodeRoleListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated NodeRoleSearchValidate searchValidate) {
        PageResult<NodeRoleListedVo> list = iNodeRoleService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="节点用户、角色、岗位关联详情")
    public AjaxResult<NodeRoleDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        NodeRoleDetailVo detail = iNodeRoleService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "节点用户、角色、岗位关联新增")
    @PostMapping("/add")
    @ApiOperation(value="节点用户、角色、岗位关联新增")
    public AjaxResult<Object> add(@Validated @RequestBody NodeRoleCreateValidate createValidate) {
        iNodeRoleService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "节点用户、角色、岗位关联编辑")
    @PostMapping("/edit")
    @ApiOperation(value="节点用户、角色、岗位关联编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody NodeRoleUpdateValidate updateValidate) {
        iNodeRoleService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "节点用户、角色、岗位关联删除")
    @PostMapping("/del")
    @ApiOperation(value="节点用户、角色、岗位关联删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iNodeRoleService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
